package com.bzkj.common.enums;

/**
 * 单据类型枚举
 * @author cjh
 */
public enum DocumentType {
    // 采购订单
    PURCHASE_ORDER("采购订单", "PO"),
    // 采购入库单
    PURCHASE_INBOUND("采购入库单", "PI"),
    // 材料出库单
    MATERIAL_OUTBOUND("材料出库单", "MO"),
    // 产成品入库单
    FINISHED_PRODUCT_INBOUND("产成品入库单", "FPI"),
    // 销售出库单
    SALES_OUTBOUND("销售出库单", "SO"),
    // 其他入库单
    OTHER_INBOUND("其他入库单", "OI"),
    // 其他出库单
    OTHER_OUTBOUND("其他出库单", "OO"),
    // 转库单
    TRANSFER_ORDER("转库单", "TO");

    private final String description;
    private final String code;

    DocumentType(String description, String code) {
        this.description = description;
        this.code = code;
    }

    /**
     * 获取单据类型描述
     *
     * @return 单据类型描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 获取单据类型编码
     *
     * @return 单据类型编码
     */
    public String getCode() {
        return code;
    }

    /**
     * 根据编码获取单据类型
     *
     * @param code 单据类型编码
     * @return 单据类型枚举
     */
    public static DocumentType fromCode(String code) {
        for (DocumentType type : values()) {
            if (type.code.equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的单据类型编码: " + code);
    }

    @Override
    public String toString() {
        return "DocumentType{" +
                "description='" + description + '\'' +
                ", code='" + code + '\'' +
                '}';
    }
}
